package com.gzz.orchid.common.webmvc.graceful;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;

/**
 * @author higmd
 */
public class ActuatorHealthIndicator implements HealthIndicator {
    @Override
    public Health health() {
        Boolean status = cheeck();
        if (status) {
            return Health.down().withDetail("Error Code", "自定义健康检查失败").build();
        }
        return Health.up().withDetail("Error Code", "自定义健康检查成功").build();
    }

    private Boolean cheeck() {
        // 这里处理自定义的健康检查
        double random = Math.random();
        if (random * 1000 < 500) {
            System.out.println("==" + random * 1000);
            return true;
        }
        return false;
    }
}
